package tut.Struct.Struct;

import java.util.Enumeration;
import java.util.Iterator;
import java.util.Stack;

public class StackDemo {

	public static void main(String args[]) {
		Stack<String> s = new Stack<String>();

		for (int i = 0; i < 5; i++) {
			String string = "e " + i;
			s.add(string);
			s.push(string);
		}

		s.push(null);
		System.out.println(s);

		int in = 0;
		while(!s.isEmpty()) {
			in++;
			System.out.println(s.peek());
			if(in == 6) break;
		}

		System.out.println("---------");
		while(!s.isEmpty()) {
			System.out.println(s.pop());
		}

		System.out.println("---------");
		Iterator<String> iter = s.iterator();

		while (iter.hasNext()) {
			String string = (String) iter.next();
			System.out.println(string);
		}

		System.out.println("---------");
		Enumeration<String> en = s.elements();
		while(en.hasMoreElements()) {
			System.out.println(en.nextElement());
		}

		for (int i = 0; i < 5; i++) {
			String string = "e " + i;
			s.add(string);
			s.push(string);
		}

		// search
		System.out.println(s.search("e1"));
		System.out.println(s.search(new String("e 1")));
		System.out.println(s.search(null));

	}

}
